<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	template="/WEB-INF/templates/template.xhtml">
	
<ui:define name="headIncludes">
	<f:event listener="#{servicoBean.initializeForm(param.servicoId)}" type="preRenderView"/>
</ui:define>
	
	<ui:define name="pageName">#{servicoBean.acao}</ui:define>
	
	<ui:define name="buttons">
		<p:commandButton value="Salvar" style="height:28px;" action="#{servicoBean.save}" update="@this" icon="ui-icon-disk"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{servicoBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages autoUpdate="true"/>
				<h:panelGrid columns="2" style="padding:5px;">
					<h:outputText value="Código" />
					<h:outputText value="Descrição *" />
					
					<p:inputText style="width:100px;" disabled="true" value="#{servicoBean.currentServico.id}"/>
					<p:inputText style="width:410px;" value="#{servicoBean.currentServico.descricao}" required="true" requiredMessage="Informe a descrição." maxlength="40"/>
				</h:panelGrid>
			
				<h:panelGrid columns="4" style="padding:5px;">			
					<h:outputText value="Valor mão de obra" />			
					<h:outputText value="Valor do serviço *" />	
					<h:outputText value="Comissão" />	
					<h:outputText value="Tempo médio" />
					
					<pe:inputNumber style="width:120px;" value="#{servicoBean.currentServico.valorMaoObra}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." maxValue="100000"/>
					<pe:inputNumber style="width:120px;" value="#{servicoBean.currentServico.valorServico}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." required="true" requiredMessage="Informe o valor do serviço." maxValue="100000"/>
					<pe:inputNumber style="width:120px;" value="#{servicoBean.currentServico.comissao}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." maxValue="100000"/>
					<pe:inputNumber style="width:120px;" value="#{servicoBean.currentServico.tempoMedio}" decimalPlaces="0" maxValue="100000"/>
				</h:panelGrid>
	
				<h:panelGrid columns="1" style="padding:5px;">	
					<h:outputText value="Observações" />		
					<p:inputTextarea style="width:520px;height:80px;" value="#{servicoBean.currentServico.observacao}" maxlength="255"/>	
				</h:panelGrid>
				<div style="width:100%; margin-top:10px;display: inline-block;">
					<h:outputText value="Funcionários"/>
					<p:commandButton icon="ui-icon-search" value="Adicionar funcionário" 
						actionListener="#{servicoBean.openDialogListFuncionario}" immediate="true"
						style="float:right;"/>
				</div>
				<div style="padding-top:10px;">
					<p:dataTable var="funcionario" 
						value="#{servicoBean.currentFuncionarios}" 
						paginator="true" rows="10" paginatorPosition="bottom"
						emptyMessage="Não há registros" id="tableFuncionarios">
						  
						<p:column headerText="Código" style="width:150px;">  
					    	<h:outputText value="#{funcionario.id}" />  
						</p:column>  
					 
						<p:column headerText="Nome">  
					    	<h:outputText value="#{funcionario.nome}" />  
						</p:column> 	
		
						<p:column width="50" style="text-align:center;">
							<p:commandButton icon="ui-icon-trash"
								style="width: 24px; height: 24px;" 
								actionListener="#{servicoBean.removeFuncionario(funcionario.id)}" title="Remover"
								immediate="true"/>
							</p:column>
				  	</p:dataTable>
				</div>
			</div>
		</p:panel>				
	</ui:define>
		<ui:define name="popups">	
		<ui:include src="listFuncionario.xhtml"/>
		<ui:include src="formFuncionario.xhtml"/>
		<ui:include src="listCargo.xhtml"/>
		<ui:include src="formCargo.xhtml"/>
		<ui:include src="listCidade.xhtml"/>
		<ui:include src="listEstado.xhtml"/>
		<ui:include src="listPais.xhtml"/>
		<ui:include src="formCidade.xhtml"/>
		<ui:include src="formEstado.xhtml"/>
		<ui:include src="formPais.xhtml"/>
	</ui:define>
</ui:composition>